package com.lgkj.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.Marker;
import com.google.gson.Gson;
import com.lgkj.R;
import com.lgkj.bean.NearShopBean;
import com.lgkj.ui.ShopDetailsActivity;
import com.lgkj.utils.CommonUtils;


/**
 * Created by Administrator on 2017/9/12.
 */

public class ImpInfoAdapter implements AMap.InfoWindowAdapter {
    private static final String TAG="ImpInfoAdapter";
    private Context mContext;

    public ImpInfoAdapter(Context mContext) {
        this.mContext = mContext;
    }

    View infoWindow = null;

    @Override
    public View getInfoContents(Marker marker) {
        getInfoWindow(marker);
        return infoWindow;
    }

    /**
     * 监听自定义infowindow窗口的infowindow事件回调
     */
    public View getInfoWindow(Marker marker) {
        if (infoWindow == null) {
            infoWindow = LayoutInflater.from(mContext).inflate(
                    R.layout.custom_info_window, null);
        }
        render(marker, infoWindow);
        return infoWindow;
        //加载custom_info_window.xml布局文件作为InfoWindow的样式
        //该布局可在官方Demo布局文件夹下找到
    }

    /**
     * 自定义infowinfow窗口
     */
    public void render(Marker marker, View view) {
        //如果想修改自定义Infow中内容，请通过view找到它并修改
        RelativeLayout rl_cont = (RelativeLayout) view.findViewById(R.id.rl_cont);
        ImageView iv_img = (ImageView) view.findViewById(R.id.iv_img);
        ImageView iv_goto = (ImageView) view.findViewById(R.id.iv_goto);
        TextView tv_name = (TextView) view.findViewById(R.id.tv_name);
        TextView tv_sign = (TextView) view.findViewById(R.id.tv_sign);
        Log.e(mContext + "", "marker info" + marker.getTitle());
        if (marker.getTitle().equals("1")) {//附近的人
//            final NearPeopleEntity.DataBean nearPeopleEntity = new Gson().fromJson(marker.getSnippet(), NearPeopleEntity.DataBean.class);
//            Util.circularClide(mContext, iv_img, Constant.FILEPATH + nearPeopleEntity.getSmall_img());
//            tv_name.setText(nearPeopleEntity.getNickname());
//            tv_sign.setText(nearPeopleEntity.getUser_motto());
//            iv_goto.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent=new Intent(mContext, AddFriendActivity.class);
//                    intent.putExtra("friend_id",nearPeopleEntity.getId());
//                    mContext.startActivity(intent);
//                }
//            });
        } else {//附近的店
            final NearShopBean.DataBean neardian = new Gson().fromJson(marker.getSnippet(), NearShopBean.DataBean.class);
            Log.i(TAG, "render: "+neardian.toString() );
            tv_name.setText(neardian.getBarbershop_name());
            tv_sign.setText(neardian.getBarbershop_text());
            CommonUtils.LoadImage(mContext,iv_img,neardian.getBarbershop_img(),0);
            rl_cont.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, ShopDetailsActivity.class);
                    intent.putExtra("shop_name", neardian.getBarbershop_name());
                    intent.putExtra("shop_id", neardian.getId());
                    mContext.startActivity(intent);
                }
            });
        }

    }
}
